package com.finance.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author: Apollo
 * @Date: 2021/4/13
 * @Description: 创建拦截器
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object loginUser = request.getSession().getAttribute("loginUser");
        if(loginUser!=null){
            return true;
        }else {
            request.setAttribute("error","请先登录!!!");
            request.getRequestDispatcher("/BorrowerInfo/login").forward(request,response);
            return false;
        }
    }


}
